<div class="xn_c_ban_jox xn_c_ban_jox_qxsz">
  <div class="xf_ht_jr_obu_width">
    <div class="xf_ht_damem_hy_box">
      <div class="xf_ht_jbox_table">
        <table class="xf_htgl_jg_tableone_table" cellspacing="0" cellpadding="0" border="0">
          <tr>
            <td>权限组名称：</td>
            <td><input id="name" class="xfht_zr_input xfht_zr_bjqxz_w" type="text"></td>
          </tr>
          <tr>
            <td>权限组描述：</td>
            <td><input id="description" class="xfht_zr_input xfht_zr_bjqxz_w" type="text"></td>
          </tr>
        </table>
      </div>
      <div class="xf_ht_damem_hy_bott xf_ht_damem_hy_bott6">
        <div class="xf_ht_damem_hy_bott_t clr">
          <div class="xf_ht_damem_hy_bott_l">模块选择</div>
        </div>
        <div class="xf_ht_damem_hy_bott_ta3">
          <table width="100%" cellspacing="0" cellpadding="0" border="0" class="xf_mem_qx_jbox">
            #{list rightTypes, as:'rightType'}
            #{if rightType_index % 4 == 1}
            <tr>
              <td valign="middle" align="left"><input type="checkbox" id="${rightType?.id}" value="${rightType?.id}" class="xf_input_raio">
                <label for="${rightType?.id}">${rightType?.name}</label>
              </td>
              #{/if} 
              #{elseif rightType_index % 4 == 0 || rightType_index == rightTypes.size()}
              <td valign="middle" align="left"><input type="checkbox" id="${rightType?.id}" value="${rightType?.id}" class="xf_input_raio">
                <label for="${rightType?.id}">${rightType?.name}</label>
              </td>
            </tr>
              #{/elseif} 
              #{else}
              <td valign="middle" align="left"><input  type="checkbox" id="${rightType?.id}" value="${rightType?.id}" class="xf_input_raio">
                <label for="${rightType?.id}">${rightType?.name}</label>
              </td>
              #{/else} 
              #{/list}
          </table>
        </div>
      </div>
      <div class="jbox_tan_ondiv jbox_tan_width4">
        <input class="jbox_ok" type="button" onclick="addRightGroup(true)" value="确 定">
        <input class="jbox_on" type="button" value="取 消">
        <input class="jbox_okjx" type="button" onclick="addRightGroup(false)" value="确定并继续添加">
      </div>
    </div>
  </div>
</div>


<script type="text/javascript">
  $(function() {
    //关闭
    $(".xf_ht_jr_obu_r").click(function() {
      $("#xf_ht_fkzh_ttc3").hide();
    });
    
    //取消
    $(".jbox_on").click(function() {
      layer.close(pop);
    });
  });

  //添加权限组(确定|确定并继续添加)
  function addRightGroup(close) {
    var name = $("#name").val();
    if (name == "") {
      alert("权限组名称不能为空!");
      return;
    }
    
    var description = $("#description").val();
    if (description == "") {
      alert("权限组描述不能为空!");
      return;
    } 
    
    var arr = new Array();

    $("#xf_ht_fkzh_ttc3 :checkbox:checked").each(function() {
      arr.push($(this).val());
    });
    
    var ids = arr.join(",");

    $.ajax({
      url : "@{addRightGroup()}",
      type : "POST",
      data : {
        "name" : name,
        "description" : description,
        "rightModules" : ids
      },
      success : function(data) {
        if (data.code < 0) {
          alert(data.msg);

          return;
        }

        alert(data.msg);
        if (true == close) {
          layer.close(pop);
          location.reload();
        }
      },
      error : function() {
        alert("对不起，出现错误!");
      }
    });
  }
</script>